﻿Imports OpenFlashChart
Imports System.Data.OleDb

Partial Public Class getChartData
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Response.CacheControl = "no-cache"
        Dim Chart As New Graph
        Dim CD As OpenFlashChart.Charts.ChartData

        CD = New OpenFlashChart.Charts.Bar(75, "#aaaaaa", "#Bar", 2)


        Dim tagCountSql As String = "SELECT papersweeksandtags.Tag, Count(*) AS TagCount FROM papersweeksandtags GROUP BY papersweeksandtags.Tag"
        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("mobilestandardsdb").ConnectionString)
        oleDbConn.Open()
        Dim tagCountCmd As New OleDbCommand(tagCountSql, oleDbConn)
        Dim tagCountReader = tagCountCmd.ExecuteReader()
        Dim tagHash As New Hashtable
        Dim maxTagCt As Integer = 0
        Dim minTagCt As Integer = 0
        If tagCountReader.HasRows() Then
            While tagCountReader.Read()
                Chart.LabelsX.Add(tagCountReader("Tag"))
                CD.Data.Add(CInt(tagCountReader("TagCount")))
                If minTagCt = 0 Then minTagCt = CInt(tagCountReader("TagCount"))
                If minTagCt > CInt(tagCountReader("TagCount")) Then minTagCt = CInt(tagCountReader("TagCount"))
                If maxTagCt < CInt(tagCountReader("TagCount")) Then maxTagCt = CInt(tagCountReader("TagCount"))
            End While
        End If
        Chart.MaxY = maxTagCt

        Chart.Data.Add(CD)

        Response.Write(Chart.ToString)


    End Sub

End Class